Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run fusion property test with arbitrary layouters #96

Merged
merged 8 commits into from
Jan 20, 2020

Conversation

sjakobi
Copy link
Collaborator

@sjakobi sjakobi commented Nov 6, 2019

Context: #95

instance Arbitrary LayoutOptions where
arbitrary = LayoutOptions <$> oneof
[ AvailablePerLine <$> arbitrary <*> arbitrary
-- , pure Unbounded -- https://github.com/quchen/prettyprinter/issues/91
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I uncomment this, the fusion tests trigger #91:

    Shallow fusion does not change rendering: FAIL (0.02s)
      *** Failed! (after 56 tests):
      Exception:
        »SFail« must not appear in a rendered »SimpleDocStream«. This is a bug in the layout algorithm! Please report this as a bug
        CallStack (from HasCallStack):
          error, called at src/Data/Text/Prettyprint/Doc/Render/Util/Panic.hs:13:21 in prettyprinter-1.5.1-inplace:Data.Text.Prettyprint.Doc.Render.Util.Panic
      oakland <(commence   inverse)>buttonaccrue tapewormtrackercrowfoot
      spheroid ( printer ` ""sailboatbackfieldendorse transit gazelletacticsdrumbeat  dogsled  dropper puppy dashboard  
       skydive miser eyeglass apple guidancetonic
      oakland southward )
      woodlark
      minnow
      slowdown
      <function>
      LayoutOptions {layoutPageWidth = Unbounded}
      Exception thrown while showing test case:
        »SFail« must not appear in a rendered »SimpleDocStream«. This is a bug in the layout algorithm! Please report this as a bug
        CallStack (from HasCallStack):
          error, called at src/Data/Text/Prettyprint/Doc/Render/Util/Panic.hs:13:21 in prettyprinter-1.5.1-inplace:Data.Text.Prettyprint.Doc.Render.Util.Panic
      
      Use --quickcheck-replay=857723 to reproduce.

Two things could IMHO help analyzing these failures:

  1. Shrinking: I wonder whether it might be easiest to just use hedgehog instead of QuickCheck, since that has built-in shrinking. What do you think about this @quchen?

  2. A diagnostic representation of the Doc (A diagnostic representation for "Doc" #90).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The arabitrary should be explicit ranges, otherwise you get ribbons of 1e-5 and 2 for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The arabitrary should be explicit ranges, otherwise you get ribbons of 1e-5 and 2 for example.

Why would that be a problem? I don't really understand the ribbon width logic so far, but I know that layoutWadlerLeijen clamps the result to a valid range:

ribbonWidth = case pWidth of
AvailablePerLine lineLength ribbonFraction ->
(Just . max 0 . min lineLength . round)
(fromIntegral lineLength * ribbonFraction)
Unbounded -> Nothing

I usually try to not to constrain the generated values unless they cause problems – "nonsense" inputs are often helpful at finding bugs in edge cases.

@quchen
Copy link
Owner

quchen commented Nov 7, 2019

I haven’t used Hedgehog and I’m fairly familiar with Quickcheck, but certainly not opposed to using new technology in order to improve tests. Automatic shrinking does sound cool, I should read up on that!

@sjakobi sjakobi force-pushed the sjakobi/arbitrary-layouters branch from 92dd87b to 4cd68f6 Compare January 20, 2020 02:53
@sjakobi
Copy link
Collaborator Author

sjakobi commented Jan 20, 2020

I'd like to build on this in my PRs, so I'll merge soon. Further improvements will hopefully happen as I use these tests.

Regarding shrinking: genericShrink will probably break invariants and lead to the wrong problems. Maybe I should write a shrinker by hand. hedgehog still seems attractive too…

@sjakobi sjakobi merged commit 7d2225b into quchen:master Jan 20, 2020
@sjakobi sjakobi deleted the sjakobi/arbitrary-layouters branch January 20, 2020 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants